#include "Container.h"
#include <GL/glew.h>

Container::Container(): width(MIN_SIZE), height(MIN_SIZE), depth(MIN_SIZE), drawMode(true), minDist(40){}

Container::Container(float x, float y, float z, bool b, float dist){
	width = x/2.f;
	height = y/2.f;
	depth = z/2.f;
	drawMode = b;
	minDist = dist;
}

void Container::changeDrawMode(){
	drawMode = !drawMode; 
}

glm::vec3 Container::getNormal(glm::vec3 position){

	glm::vec3 dist(width - fabs(position.x), height - fabs(position.y), depth - fabs(position.z));
	glm::vec3 normal(0, 0, 0);

	if (dist.x < minDist)
		normal.x = 1.f - normal.x/minDist;
	if (dist.y < minDist)
		normal.y = 1.f - normal.y/minDist;
	if (dist.z < minDist)
		normal.z = 1.f - normal.z/minDist;

	if (position.x > 0) 
		normal.x = -normal.x;
	if (position.y > 0) 
		normal.y = -normal.y;
	if (position.z > 0) 
		normal.z = -normal.z;

	return normal;
}

void Container::draw(){

	if (!drawMode) return;

	//glLineWidth(2.0);     
	glColor3f(0.5, 0.5, 0.5);

	glBegin(GL_LINE_STRIP); 
		glVertex3f(-width, -height, -depth);
		glVertex3f(width, -height, -depth);
		glVertex3f(width, height, -depth);
		glVertex3f(-width, height, -depth);
		glVertex3f(-width, -height, -depth);
	glEnd();
  
	glBegin(GL_LINE_STRIP);
		glVertex3f(-width, -height, depth);
		glVertex3f(width, -height, depth);
		glVertex3f(width, height, depth);
		glVertex3f(-width, height, depth);
		glVertex3f(-width, -height, depth);
	glEnd();

	glBegin(GL_LINES);               
		glVertex3f(-width, -height, depth);
		glVertex3f(-width, -height, -depth);
		glVertex3f(-width, height, depth);
		glVertex3f(-width, height, -depth);
		glVertex3f(width, -height, depth);
		glVertex3f(width, -height, -depth);
		glVertex3f(width, height, depth);
		glVertex3f(width, height, -depth);
	glEnd();

}

void Container::collide(){}

float Container::MIN_SIZE = 50;

Container *Container::instance = NULL;